import logging
import time
import os

class Logger():

    def __init__(self):
        # 记录器
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.DEBUG)

        # 处理器
        ch = logging.StreamHandler()
        ch.setLevel(logging.INFO)
        log_path = os.path.abspath('log')
        if os.path.lexists(log_path) == False:
            os.makedirs(log_path)
        fh = logging.FileHandler('{}\{}.log'.format(log_path,time.strftime("%Y-%m-%d")), encoding='utf-8')
        fh.setLevel(logging.INFO)

        # 日志输出格式
        formatter = logging.Formatter("%(asctime)s|%(levelname)s|%(filename)s|%(lineno)s|%(message)s")

        # 处理器设置日志格式
        ch.setFormatter(formatter)
        fh.setFormatter(formatter)

        # 把处理器添加到记录其中
        self.logger.addHandler(ch)
        self.logger.addHandler(fh)

logger = Logger().logger